$(document).ready(function(){
    $("#assigned_user_name").autocomplete({
        source: function( request, response ) {
            $.ajax({
                url: "index.php?module=Accounts&action=loadUsersFromCities&to_pdf=true",
                dataType: "json",
                data: {
                        cityId: $('#city_id').val(),
                        //cityId: "f278ca06-8a6a-346f-fae8-4d89eaebadec",
                        term: request.term
                },
                success: function( data ) {
                    response(data);
                }
            });

        },
        //source: "index.php?module=Accounts&action=loadUsersFromCities&to_pdf=true&cityId=f278ca06-8a6a-346f-fae8-4d89eaebadec",
        select: function( event, ui ) {
            if(ui.item){
                if(ui.item.value != "" && ui.item.label != "Wybierz najpierw miasto"){
                    $('#assigned_user_id').val(ui.item.value);
                    $('#assigned_user_name').val(ui.item.label);
                }else{
                   $('#assigned_user_id').val('');
                    $('#assigned_user_name').val('');
                }
            }
            return false;
        },
        focus: function( event, ui ){
            $('#assigned_user_name').val(ui.item.label);
            return false;
        }
    });
    
    customListView();
    
});